import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  Req,
} from '@nestjs/common';
import { FolderService } from './folder.service';
import { CreateFolderDto } from './dto/create-folder.dto';
import { Request } from 'express';
import { UpdateFolderDto } from './dto/update-folder.dto';
import { CreateGroupToFolderlistDto } from './dto/create-grouptofolder.dto';

@Controller('folder')
export class FolderController {
  constructor(private readonly folderService: FolderService) {}

  @Post('createFolder')
  createFolder(
    @Body() createFolderDto: CreateFolderDto,
    @Req() request: Request,
  ) {
    createFolderDto.creator = (request as any).user.email;
    return this.folderService.createFolder(createFolderDto);
  }

  // 获取个人用户下边的根路径文件夹
  @Get('getRootFolderByUser')
  getRootFolderByUser(@Req() request: Request) {
    return this.folderService.getRootFolderByUser((request as any).user.email);
  }

  //获取个人用户下的对应路径文件夹
  @Get('getFolderUserByFolderuuid/:folderuuid')
  getFolderUserByPath(
    @Param('folderuuid') folderuuid: string,
    @Req() request: Request,
  ) {
    return this.folderService.getFolderUserByFolderuuid(
      folderuuid,
      (request as any).user.email,
    );
  }

  @Get('getFolderById/:id')
  getFolderById(@Param('id') id: string) {
    return this.folderService.getFolderById(id);
  }

  @Get('getChildFolderuuidByFolderuuid/:folderuuid')
  getChildFolderuuidByFolderuuid(@Param('folderuuid') folderuuid: string) {
    return this.folderService.getChildFolderuuidByFolderuuid(folderuuid)
  }

  @Patch('updateFolder/:id')
  updateFolder(
    @Param('id') id: string,
    @Body() updateFolderDto: UpdateFolderDto,
  ) {
    return this.folderService.updateFolder(id, updateFolderDto);
  }

  @Delete('deleteFolder/:id')
  deleteFolder(@Param('id') id: string) {
    return this.folderService.deleteFolder(id);
  }

  // 设置小组和文件夹之间关系
  @Delete('deleteFolderItemFromGroup/:folderuuid')
  deleteFolderItemFromGroup(
    @Param('folderuuid') folderuuid: string,
  ) {
    return this.folderService.deleteFolderItemFromGroup(folderuuid);
  }

  @Get('getFolderItemByGroupuuidFolderuuid/:groupuuid/:folderuuid')
  getFolderItemByGroupuuidFolderuuid(@Param('groupuuid') groupuuid: string,@Param('folderuuid') folderuuid: string,) {
    return this.folderService.getFolderItemByGroupuuidFolderuuid(groupuuid, folderuuid);
  }

  @Post('moveFolderToGroup')
  moveFolderToGroup(
    @Body() createGroupToFolderlistDto: CreateGroupToFolderlistDto,
    @Req() request: Request,
  ) {
    createGroupToFolderlistDto.belong = (request as any).user.email;
    return this.folderService.moveFolderToGroup(createGroupToFolderlistDto);
  }

  @Post('moveFolderItemToUser')
  moveFolderItemToUser(
    @Body() createFolderDto: CreateFolderDto,
    @Req() request: Request,
  ) {
    return this.folderService.moveFolderItemToUser(
      createFolderDto,
      (request as any).user.email,
    );
  }

  @Post('createFolderToGroup/:groupuuid')
  createFolderToGroup(
    @Body() createFolderDto: CreateFolderDto,
    @Param('groupuuid') groupuuid: string,
    @Req() request: Request,
  ) {
    createFolderDto.creator = (request as any).user.email;
    return this.folderService.createFolderToGroup(createFolderDto, groupuuid);
  }

  @Get('getChildFolderByFolderuuid/:folderuuid')
  getChildFolderByFolderuuid(@Param('folderuuid') folderuuid: string) {
    return this.folderService.getChildFolderByFolderuuid(folderuuid);
  }
}
